<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<meta charset="utf-8" />
		<script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/jquery-1.11.1.min.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/jquery.metadata.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/jquery.validate.min.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/jquery-migrate-1.1.0.min.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/jquery.jqprint-0.3.js"></script>
		<title>科目列表</title>
		
		<script>
		$(function() {
			
			$(".toTest").each(function(){
		 		   $(this).click(function(){
		 			  if(confirm("是否确认参加该科目考试？")){
		 			  }else{
		 				  $(this).attr("href","");
		 			  }
		  		  })
		    });
			
			//点击按钮后。在modal里面更新数据
			$('.showScoreBtn').click(function() {
				var scoreId = $(this).attr('scoreId');
				$.ajax({
					type: 'POST',
					url: '${pageContext.request.contextPath}/student/showScore',
					data: {
						scoreId: scoreId
					},
					dataType: "json",
					success: function(data){
						$('#userName').text(data.userName);
						$('#subjectName').text(data.subjectName);
						$('#examTime').text(data.examTimeString);
						$('#score').text(data.score);
						$('#showScoreModal').modal('show');
					}
				});
			});
				
			//使用jqprint打印modal框内的内容
			$('#scorePrint').click(function() {
				$('#showScoreModal .modal-body').jqprint();
			});
		});
		</script>
	</head>

	<body class="no-skin">
		<!-- /section:basics/sidebar -->
								<div class="row">
									<div id="messageDiv"><c:if test="${score != null }"><script type="text/javascript">alert('考试分数为：${score.score}');</script></c:if></div>
									<div class="col-xs-12">
										<table id="sample-table-1" class="table table-striped table-bordered table-hover">
											<thead>
												<tr>
													<th>科目编号</th>
													<th>科目名</th>
													<th>科目描述</th>
													<th>科目题数</th>
													<th>总时长</th>
													<th>潢分总分</th>
													<th>是否开启考试</th>
													<th>本科目得分</th>
													<th>是否已参考</th>
													<th>操作</th>
												</tr>
											</thead>
											
											<tbody>
												<c:forEach items="${subjectList}" var="sub">
												<tr>
													<td>${sub.subId }</td>
													<td>${sub.name }</td>
													<td>${sub.description }</td>
													<td>${sub.testCount }</td>
													<td>${sub.totalTime }</td>
													<td>${sub.totalScore }</td>
													<td>
														<%--if () else if () else if ()     else  --%>
														<c:choose>
															<c:when test="${sub.status == 0 }">
																<label class="label arrowed">已关闭</label>
															</c:when>
															<c:otherwise>
																<label class="label label-success arrowed-in arrowed-in-right">已开启</label>
															</c:otherwise>
														</c:choose>
													</td>
													<td>${sub.scoreVO.score }</td>
													<td>
														<c:choose>
															<c:when test="${sub.scoreVO == null }">
																<label class="label label-success arrowed-in arrowed-in-right">未参考</label>
															</c:when>
															<c:otherwise>
																<label class="label arrowed">已参考</label>
															</c:otherwise>
														</c:choose>
													</td>
													<td>
														<c:choose>
															<c:when test="${sub.scoreVO == null }">
																<c:choose>
																	<c:when test="${sub.status == 0 }">
																		<a title="进入考试" disabled="disabled" class="btn btn-success btn-xs"><i class="ace-icon fa fa-pencil"></i></a>
																	</c:when>
																	<c:otherwise>
																		<a title="进入考试" href="${pageContext.request.contextPath}/student/toTest/${sub.subId }" class="btn btn-success btn-xs toTest"><i class="ace-icon fa fa-pencil"></i></a>
																	</c:otherwise>
																</c:choose>
															</c:when>
															<c:when test="${empty sub.scoreVO.score && sub.scoreVO.remainingExamTime > 0}">
																<!--已经开始考试，中途关闭-->
																<a title="进入考试" href="${pageContext.request.contextPath}/student/toTest/${sub.subId }" class="btn btn-success btn-xs"><i class="ace-icon fa fa-pencil"></i></a>
															</c:when>
															<c:otherwise>
																<a title="查看成绩" scoreId="${sub.scoreVO.id }" class="btn btn-info btn-xs showScoreBtn"><i class="ace-icon fa fa-eye"></i></a>
															</c:otherwise>
														</c:choose>
													</td>
												</tr>
												</c:forEach></tbody></table>
									</div>
								</div><!-- /.row -->

		<div class="modal fade" id="showScoreModal" tabindex="-1" role="dialog" aria-labelledby="showScoreModalLabel" aria-hidden="true">
  			  <div class="modal-dialog">
   			     <div class="modal-content">
         			   <div class="modal-header">
         			   		   <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
             				   <h4 class="modal-title" id="showScoreModalLabel">查看科目成绩</h4>
          			  </div>
           			  <div class="modal-body">
           			  	<p><label>用户名:</label><label id="userName">Enkidu</label></p>
           			  	<p><label>科目名:</label><label id="subjectName">English</label></p>
           			  	<p><label>考试时间:</label><label id="examTime">2016-06-08</label></p>
           			  	<p><label>得分:</label><label id="score">140</label></p>
           			  </div>
            		  <div class="modal-footer">
                		  <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                		  <button id="scorePrint" type="button" class="btn btn-primary" data-dismiss="modal">打印</button>
            		</div>
       		 	</div><!-- /.modal-content -->
   			</div><!-- /.modal -->
		</div>								
		
	</body>
</html>
